﻿CREATE FUNCTION [dbo].[fs_List_Base](
	@StateID int
)RETURNS TABLE AS
RETURN (
SELECT
LIST.LoanID,
LIST.UsixID,
LIST.U,
LIST.FirstName AS [First Name],
LIST.LastName AS [Last Name],
CONVERT(varchar, LIST.StatusDate, 111) AS [Date In], 
LIST.StatusUser AS [User],
LIST.BatchID AS BID,
LIST.ContractHolder,
LIST.Dealer,
LIST.VIN,
LIST.Description
FROM         v_List_Base AS LIST INNER JOIN
                      dbo.fs_Loans_Read(DEFAULT, @StateID) AS LOANS ON LIST.LoanID = LOANS.LoanID
/*
INNER JOIN
                          (SELECT     LoanID, MenuID, COUNT(*) AS Count
                            FROM          t_Loan_Menus
                            GROUP BY LoanID, MenuID
                            HAVING      (MenuID = @MenuID)) AS MENU_COUNT ON v_List_Base.LoanID = MENU_COUNT.LoanID LEFT OUTER JOIN
                          (SELECT     LoanID, MAX(DateStamp) AS DateStamp
                            FROM          t_Notes AS t_Notes_1
                            GROUP BY LoanID) AS t_Notes ON v_List_Base.LoanID = t_Notes.LoanID
*/
)











